package com.study.csc.a05threadPriority2;

/**
 * @author csc
 * @Date 2023/10/28 15:50
 * @PackageName:com.study.csc.a05threadPriority2
 * @ClassName: TestPriority
 * @Description: 测试线程优先级
 * @Version 1.0
 */
public class TestPriority {


    public static void main(String[] args) {
        //主线程默认优先级
        System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());


        Mypriority mypriority = new Mypriority();

        Thread t1 = new Thread(mypriority);
        Thread t2 = new Thread(mypriority);
        Thread t3 = new Thread(mypriority);
        Thread t4 = new Thread(mypriority);
        Thread t5 = new Thread(mypriority);

        //先设置优先级
        t1.start();

        t2.setPriority(1);
        t2.start();

        t3.setPriority(4);
        t3.start();

        t4.setPriority(Thread.MAX_PRIORITY);//10
        t4.start();

        t5.setPriority(-1);
        t5.start();



    }


}

class Mypriority implements Runnable{
    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+"--->"+Thread.currentThread().getPriority());
    }
}
